#include "mouse.h"

DEFINE_SINGLETON(Mouse);

Mouse::Mouse(const string& name, ClassId* classId):
Instance(name, classId)
{
    // NOOP
}

Mouse::~Mouse()
{
    // NOOP
}

void Mouse::handleButtonEvent(SDL_MouseButtonEvent* event, float dt)
{
    assert(event);
    Window* window = Window::getFromId(event->windowID);
    Mouse* mouse = Mouse::getActive();
    if(!mouse)
        return;
    switch (event->type) {
        case SDL_MOUSEBUTTONDOWN:
            mouse->onButtonDown(window, event->button, event->x, event->y, dt);
            break;
        case SDL_MOUSEBUTTONUP:
            mouse->onButtonUp(window, event->button, event->x, event->y, dt);
            break;
    }
}

void Mouse::onButtonDown(Window* window, Uint8 button, int x, int y, float dt)
{
}

void Mouse::onButtonUp(Window* window, Uint8 button, int x, int y, float dt)
{
}

void Mouse::handleMotionEvent(SDL_MouseMotionEvent* event, float dt)
{
    assert(event);
    Window* window = Window::getFromId(event->windowID);
    Mouse* mouse = Mouse::getActive();
    if(!mouse)
        return;
    mouse->onMotion(window, event->xrel, event->yrel, event->x, event->y, dt);
}

void Mouse::onMotion(Window* window, int dx, int dy, int x, int y, float dt)
{
}

void Mouse::handleWheelEvent(SDL_MouseWheelEvent* event, float dt)
{
    assert(event);
    Window* window = Window::getFromId(event->windowID);
    Mouse* mouse = Mouse::getActive();
    if(!mouse)
        return;
    mouse->onWheel(window, event->x, event->y, dt);
}

void Mouse::onWheel(Window* window, int dx, int dy, float dt)
{
}

bool Mouse::load(DataStream* ds)
{
    INSTANCE_LOAD(ds);

    return true;
}

bool Mouse::save(DataStream* ds)
{
    INSTANCE_SAVE(ds);

    return true;
}
